﻿using System;
using System.Net;
using System.Windows;
using System.Data.Linq.Mapping;
using System.ComponentModel;
using System.Data.Linq;

namespace STS.Model
{
    [Table]
    public class Lek : INotifyPropertyChanged, INotifyPropertyChanging
    {
        public Lek()
        {
            poraIloscArray = new EntitySet<PoraIlosc>(
                new Action<PoraIlosc>(this.Attach_PoraIloscArray),
                new Action<PoraIlosc>(this.Detach_PoraIloscArray)
                );
        }

        // add operation - poraIlosc
        private void Attach_PoraIloscArray(PoraIlosc p)
        {
            NotifyPropertyChanging("PoraIloscArray");
            p.Lek = this;
        }

        // remove operation - poraIlosc
        private void Detach_PoraIloscArray(PoraIlosc p)
        {
            NotifyPropertyChanging("PoraIloscArray");
            p.Lek = null;
        }

        private int id;

        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int Id
        {
            get { return id; }
            set
            {
                if (id != value)
                {
                    NotifyPropertyChanging("Id");
                    id = value;
                    NotifyPropertyChanged("Id");
                }
            }
        }

        private string opis;

        [Column]
        public string Opis
        {
            get { return opis; }
            set
            {
                if (opis != value)
                {
                    NotifyPropertyChanging("Opis");
                    opis = value;
                    NotifyPropertyChanged("Opis");
                }
            }
        }

        private string url;

        [Column]
        public string Url
        {
            get { return url; }
            set
            {
                if (url != value)
                {
                    NotifyPropertyChanging("Url");
                    url = value;
                    NotifyPropertyChanged("Url");
                }
            }
        }

        private string nazwa;

        [Column]
        public string Nazwa
        {
            get { return nazwa; }
            set
            {
                if (nazwa != value)
                {
                    NotifyPropertyChanging("Nazwa");
                    nazwa = value;
                    NotifyPropertyChanged("Nazwa");
                }
            }
        }

        private EntitySet<PoraIlosc> poraIloscArray;

        [Association(Storage = "poraIloscArray", OtherKey = "_lekId", ThisKey = "Id", DeleteRule = "CASCADE")]
        public EntitySet<PoraIlosc> PoraIloscArray
        {
            get { return this.poraIloscArray; }
            set { this.poraIloscArray.Assign(value); }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public event PropertyChangingEventHandler PropertyChanging;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void NotifyPropertyChanging(string propertyName)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }

        public override string ToString()
        {
            return String.Format("Id: {0} Nazwa: {1} Opis: {2} url: {3}",Id, Nazwa, Opis,Url);
        }
    }


}
